import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'sort_item_data.dart';
import 'sort_list.dart';

Future<List<T>> showSortList<T>(
  BuildContext context, {
  @required String title,
  @required List<SortItemData<T>> items,
}) {
  return Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => _SortListPage<T>(title: title, items: items),
      ));
}

class _SortListPage<T> extends StatefulWidget {
  final List<SortItemData<T>> items;
  final String title;

  const _SortListPage({
    Key key,
    @required this.items,
    @required this.title,
  }) : super(key: key);

  @override
  _SortListPageState<T> createState() => _SortListPageState<T>();
}

class _SortListPageState<T> extends State<_SortListPage<T>> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(
        title: widget.title,
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: SortList(
              items: widget.items,
            ),
          ),
          FixedBottomBtn(
            title: '保 存',
            onTap: () async {
              Navigator.pop(context, widget.items.map((item) => item.value).toList());
            },
          ),
        ],
      ),
    );
  }
}
